package com.lgw.coupon.controller;

import com.lgw.commons.model.domain.ResultInfo;
import com.lgw.commons.utils.ResultInfoUtil;
import com.lgw.coupon.service.ITemplateService;
import com.lgw.coupon.vo.TemplateRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@RestController
public class CouponTemplateController {

    @Autowired
    private ITemplateService templateService;

    @Autowired
    private HttpServletRequest request;

    /**
     * 构建优惠券模板
     *
     * @param templateRequest
     * @return
     */
    @PostMapping("/build")
    public ResultInfo buildTemplate(@RequestBody TemplateRequest templateRequest) {
        return ResultInfoUtil.buildSuccess(request.getServletPath(), templateService.buildTemplate(templateRequest));
    }

    /**
     *构建优惠券模板详情
     *
     * @param id
     * @return
     */
    @GetMapping("/info")
    public ResultInfo buildTemplateInfo(@RequestParam(name = "id")Integer id) {
        return ResultInfoUtil.buildSuccess(request.getServletPath(),templateService.getTemplateInfo(id));
    }

    @GetMapping("/sdk/all")
    public ResultInfo findAllUableTemplate(){
        return ResultInfoUtil.buildSuccess(request.getServletPath(),templateService.findAllUsableTemplate());
    }

}
